#include <vector>
#include "Thread.hpp"

using namespace ThreadModule;

const int num = 10;

void Pirnt(int cnt)
{
    while(cnt)
    {
        std::cout<<"cnt is : " << cnt--<< std::endl;
    }
    std::cout<< std::endl;
}
    
int main()
{
    std::vector<Thread<int>> threads;
    //1.create a lot of threads
    for(int i = 0; i < num; i++)
    {
        std::string name = "thread - " + std::to_string(i+1);
        threads.emplace_back(Pirnt,3,name);
    }

    //2.strat a lot of threads
    for(auto& thread : threads)
    {
        thread.Strat();
        sleep(1);
    }

    //3.wait a lot of threads
    for(auto& thread : threads)
    {
        thread.Join();
        std::cout << "wait thread success, name : " << thread.name() << std::endl;
        sleep(1);
    }
    return 0;
}

















// using namespace ThreadModule;

// const int num = 10;

// void Print(int& cnt)
// {
//     while(cnt)
//     {
//         std::cout<<"cnt :" << cnt--<<std::endl;
//     }
// } 

// int main()
// {
//     std::vector<Thread<int>> threads;
//     //1.创建一批线程
//     for(int i = 0; i < num; i++)
//     {
//         std::string name = "thread-"+std::to_string(i+1);
//         threads.emplace_back(Print,5,name);
//     }

//     //2.启动一些线程
//     for(auto& thread:threads)
//     {
//         thread.Strat();
//         thread.Excute();
//         std::cout<<std::endl;
//         //sleep(1);
//     }

//     //3.等待一批线程
//     for(auto& thread:threads)
//     { 
//         sleep(1);
//         thread.Join();
//         std::cout << "wait thread done, thread is: " << thread.name() << std::endl;
//     }
// }